from django.conf import settings
from django.contrib import admin
from django.conf.urls.defaults import patterns, include, url
from django.contrib.auth.decorators import login_required
from django.views.generic import TemplateView
from flckr.gallery_site.views import *

admin.autodiscover()

# common urls
urlpatterns = patterns(
    '',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('registration.urls')),
    url(r'^messages/', include('messages.urls')),
    url(r'^comments/', include('django.contrib.comments.urls')),
    url(r'^$', TemplateView.as_view(template_name='index.html')),
)

# gallery urls
urlpatterns += patterns(
    '',
    url(r'list/$', GalleryList.as_view(), name='gallery_list'),
    url(r'^gallery/add/$',
        login_required(PersonalPhotoCreate.as_view()), name='photo_add'),
    url(r'^gallery/(?P<username>\w+)/$',
        PersonalPhotoList.as_view(), name='gallery'),
    url(r'^gallery/(?P<username>\w+)/(?P<slug>[\-\w\d]+)/$',
        PersonalPhotoDetail.as_view(), name='personal_photo'),
    url(r'^gallery/(?P<username>\w+)/(?P<slug>[\-\w\d]+)/like/$',
        PersonalPhotoRate.as_view(rate=1), name='like'),
    url(r'^gallery/(?P<username>\w+)/(?P<slug>[\-\w\d]+)/dislike/$',
        PersonalPhotoRate.as_view(rate=-1), name='dislike'),
)

# serving static files from media if developing server
if settings.DEBUG:
    urlpatterns += patterns('',
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.MEDIA_ROOT,
        }),
    )
